<template>
	<view>
		<Navbar></Navbar>
		<view class="u-m-20">
			<view class="u-card-box u-m-t-30">
				<view class="u-flex u-row-between u-col-top u-p-b-10">
					<view>
						<u-image width="140rpx" height="140rpx" border-radius="20"
							:src="thanksData.head_img"></u-image>
						<view class="u-text-center u-font-24 u-m-t-15 number_box">
							<view class="u-font-bold u-font-26">{{thanksData.number}}</view>
							<view class="u-font-23 u-m-l-5">能量值</view>
						</view>
					</view>
			
					<view class="u-m-l-20 u-flex-1 u-flex-col u-row-between u-ellipsis">
						<view class="u-font-bold u-font-34 u-flex">
							<view class="u-m-r-10">{{ thanksData.name }}</view>
							<!-- <view class="u-m-r-10" v-if="thanksData && ![0,'0'].includes(thanksData.sex)">
								<u-icon size="32" :color="thanksData.sex == 1 ? '#4399FF' : '#FF69B1'"
									:name="thanksData.sex == 1 ? 'nanxing' : 'nvxing'"
									custom-prefix="custom-icon" />
							</view> -->
							<view class="u-m-r-10" v-if="thanksData.is_authentication == 2">
								<u-icon size="32" color="#FB6316" name="renzheng" custom-prefix="custom-icon" />
							</view>
							<view class="u-m-r-10" v-if="thanksData.is_company_user == 1">
								<u-icon size="32" color="#F8494D" name="qiye1" custom-prefix="custom-icon" />
							</view>
							<view class="u-tag-box" :class="thanksData.president_class"
								v-if="[5,6,7,8].includes(thanksData.president_status) && thanksData.president_class">
								{{ getPresidentName(thanksData.partner_status, thanksData.president_status) }}
							</view>
						</view>
						<view class="u-m-t-12 u-flex u-row-between u-ellipsis">
							<view class="u-m-r-10 u-ellipsis">{{thanksData.address}}</view>
							<view v-if="thanksData.is_friend == 0 && !isPromoter">
								<u-icon name="man-add-fill" color="#F96257" size="60"
									@click.native.stop="addPerson()"></u-icon>
							</view>
							<view v-else>
								<u-icon name="bodadianhua" custom-prefix="custom-icon" color="#F96257" size="60"
									@click.native.stop="callMobile(thanksData.phone)"></u-icon>
							</view>
						</view>
						<view class="u-m-t-20 u-flex u-row-around u-width-100">
							<view class="u-text-center">
								<view class="u-color-gray u-font-24">举办酒局</view>
								<view class="u-font-bold u-font-34 u-m-t-10">{{thanksData.data_num.space || 0}}场</view>
							</view>
							<view class="line"></view>
							<view class="u-text-center">
								<view class="u-color-gray u-font-24">参与酒局</view>
								<view class="u-font-bold u-font-34 u-m-t-10">{{thanksData.data_num.join_num || 0}}场</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="u-m-30 u-card-box" v-for="item in list" :key="item.id">
			<view class="u-flex u-row-between">
				<view class="u-flex">
					<u-image width="70rpx" height="70rpx" border-radius="20"
						:src="item.user.head_img" @click="onViewUser(item.user.id)"></u-image>
					<view class="u-m-l-20">{{item.user.name}}</view>
					<view class="u-m-l-20">+{{item.num}}</view>
				</view>
				<view class="u-flex">
					<view>{{item.create_time.slice(0,11)}}</view>
					<view class="u-m-l-20 u-p-l-20 u-p-r-20 common_tag u-back-red u-color-white" @click="onReturnThank(item.user)" v-if="isPromoter">回谢</view>
				</view>
			</view>
			<view class="u-m-t-15" v-if="item.content">{{item.content}}</view>
		</view>
		<Loadmore :status="status"></Loadmore>
		<view style="height: 200rpx;"></view>
		<Bottom :btnText="'返回'" @confirm="confirm"></Bottom>
		
		<!-- 通用提示框 -->
		<Modal :show="modal.show" :confirmText="modal.confirm" :cancelText="modal.cancel" :modalContent="modal.content"
			:showCancel="modal.showCancel" :maskAble="modal.maskAble" @confirm="modalConfirm" @cancel="modalCancel"
			@modeClose="modeClose"></Modal>
			
		<!-- 礼物感谢框 -->
		<GiftPopup :show="giftShow" :status="giftBtnStatus" :data="gift" @onCloseGift="onGiftClose" @onGiftChoose="onGiftChoose"></GiftPopup>
	</view>
</template>

<script>
	import Navbar from '@/components/Navbar.vue'
	import Bottom from '@/components/Bottom.vue'
	import Loadmore from '@/components/Loadmore.vue'
	import Modal from '@/components/Modal.vue'
	import GiftPopup from '../components/GiftPopup.vue'
	import ActivityList from '@/pages/demand/component/ActivityList.vue'
	import reachBottom from '@/mixins/reachBottom.js'
	import { userFriendDetail, userGiftLog, singleIntegral, userGiveGift, giftList } from '@/network/api.js'
	import { pointTransform, call, presidentClass, PresidentLevel, TeaStatus } from '@/utils/index.js'
	export default{
		mixins:[reachBottom],
		components:{
			Navbar,
			Bottom,
			ActivityList,
			Loadmore,
			Modal,
			GiftPopup
		},
		data(){
			return{
				id: 0,
				userId: uni.getStorageSync("user_id"),
				isPromoter: false, // 访问用户与感谢目标是否是同一个
				isReturnData: {},
				thanksData: {},
				list:[],
				modal: {
					show: false,
					showCancel: true,
					maskAble: true,
					confirm: '申请',
					cancel: '取消',
					content: ''
				},
				giftShow: false,
				gift:{
					list: [],
					checkId: 0,
					checkNum: 0,
					text: '',
					isAnonymous: false
				},
				giftBtnStatus: true
			}
		},
		onLoad(options){
			if(options.id){
				this.id = options.id
			}else{
				this.id = uni.getStorageSync("user_id")
			}
			this.getUserData()
			this.getUserGiftList()
		},
		methods:{
			async getUserData(){
				const params = {
					user_id: this.id,
					from_user_id: this.userId 
				}
				const res = await userFriendDetail(params)
				res.data.number = pointTransform(res.data.number)
				res.data.president_status = parseInt(res.data.president_status)
				res.data.president_class = presidentClass(res.data.president_status)
				this.thanksData = res.data
				if(Number(res.data.id) == Number(this.userId)){
					this.isPromoter = true
				}
			},
			getPresidentName(status1, status2) {
				// return PresidentLevel(status)
        return TeaStatus(status1, status2)  
			},
			async getUserGiftList(){
				const params = {
					user_id: this.id,
					page: this.page,
					limit: this.pageSize
				}
				const res = await userGiftLog(params)
				this.count = res.data.count
				res.data.list.map(item=>{
					this.list.push(item)
				})
				if(this.count == this.list.length){
					this.status = 'nomore'
				}
			},
			callMobile(val) {
				call(val)
			},
			onViewUser(id){
				if(this.isPromoter){
					uni.navigateTo({
						url: "/teaBureau/teaPersonDetail/teaPersonDetail?id=" + id
					})
				}
			},
			addPerson() {
				/* 添加好友 */
				/* const params = {
					key: "ExchangeCards",
					type: 0
				}
				singleIntegral(params).then(res => {
					this.modal.content = `交换名片需要消耗${res.data.value}积分，请问是否仍要继续？`
					this.modal.show = true
				}) */
				this.modal.content = `交换名片，对方同意后交换成功`
				this.modal.show = true
			},
			async chooseThank(){
				/* 打开感谢框 */
				const res = await giftList()
				res.data.map(item=>{
					item.check = false
				})
				res.data.push({id:9527,name:'自定义积分',num: '',check: false})
				this.gift.list = res.data
				this.giftShow = true
			},
			async onReturnThank(val){
				this.isReturnData = val
				const res = await giftList()
				res.data.map(item=>{
					item.check = false
				})
				res.data.push({id:9527,name:'自定义积分',num: '',check: false})
				this.gift.list = res.data
				this.giftShow = true
			},
			async onGiftChoose(val){
				if(val.checkNum){
					this.giftBtnStatus = false
					const params = {
						user_id: this.isPromoter ? this.isReturnData.id : this.thanksData.id,
						give_user_id: this.userId,
						num: val.checkNum,
						content: val.text,
						is_anonymous: val.isAnonymous ? 1: 2
					}
					const res = await userGiveGift(params)
					this.page = 1
					this.list = []
					this.status = 'loadmore'
					this.getUserData()
					this.getUserGiftList()
					this.gift.checkId = 0
					this.gift.checkNum = 0
					this.gift.text = ''
					this.gift.isAnonymous = true
					this.giftBtnStatus = true
					this.giftShow = false
					uni.showToast({
						title: "提交成功",
						icon: "none"
					})
				}else{
					uni.showToast({
						title: "请选择积分",
						icon: "none"
					})
				}
			},
			onGiftClose(){
				this.giftBtnStatus = true
				this.giftShow = false
			},
			confirm(){
				uni.navigateBack({
					delta: 1,
					success() {
						uni.$emit('update', {
							msg: '页面更新'
						})
					}
				})
			},
			loadData() {
				if(this.status == 'nomore') return
				this.page++
				this.status = 'loading'
				this.getUserGiftList()
			}
		},
		/* 分享好友 */
		onShareAppMessage() {
			return {
				title: `青创云店：快来围观${uni.getStorageSync("user_name")}的感谢信~`,
				path: `/teaBureau/teaThanksList/teaThanksList?id=${this.id}`,
				imageUrl: 'https://medv-new.oss-cn-shanghai.aliyuncs.com/images/common/20240624979559784584.png',
			}
		},
	}
</script>

<style>
</style>